import 'package:flutter/material.dart';
import 'package:flutter_pretty/network/dio_manager.dart';
import 'package:flutter_pretty/tabs/taba.dart';
import 'package:flutter_pretty/tabs/tabb.dart';
import 'package:flutter_pretty/tabs/tabc.dart';
import 'package:flutter_pretty/tabs/tabd.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primaryColor: Colors.blue,
        primarySwatch: Colors.green,
        highlightColor: Colors.transparent,
        splashColor: Colors.transparent,
      ),
      home: MainTabPage(),
    );
  }
}

class MainTabPage extends StatefulWidget {
  const MainTabPage({Key? key}) : super(key: key);

  @override
  _MainTabPageState createState() => _MainTabPageState();
}

class _MainTabPageState extends State<MainTabPage> {
  var _currentIndex = 0;

  @override
  void initState() {
    super.initState();
    try {
      DioManager.instance
          .get('http://www.mocky.io/v2/5d7fc75c3300000476f0b557');
    } catch (e) {
      print(e);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("Tab Demo")),
      body: IndexedStack(
        index: _currentIndex,
        children: [TabA(), TabB(), TabC(), TabD()],
      ),
      bottomNavigationBar: BottomNavigationBar(
          currentIndex: _currentIndex,
          type: BottomNavigationBarType.fixed,
          unselectedItemColor: Colors.blueGrey,
          selectedItemColor: Colors.blue,
          onTap: (int index) {
            setState(() {
              _currentIndex = index;
            });
          },
          items: [
            BottomNavigationBarItem(icon: Icon(Icons.home), label: "Home"),
            BottomNavigationBarItem(
                icon: Icon(Icons.business), label: "Business"),
            BottomNavigationBarItem(icon: Icon(Icons.school), label: "School"),
            BottomNavigationBarItem(
                icon: Icon(Icons.my_location), label: "My Location"),
          ]),
    );
  }
}
